package gazzera.swing.download;

import gazzera.swing.model.*;

import java.awt.*;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;


public class ProgressRenderer extends JProgressBar implements TableCellRenderer {

	private Border selectedBorder;
	private Border unselectedBorder;
	private Color foreground;
	
	public ProgressRenderer() {
        super();
        setOpaque(true); 
        setMinimum(0);
        foreground = this.getForeground();
        setStringPainted(true);

    }
    

    public Component getTableCellRendererComponent(
                            JTable table, Object o,
                            boolean isSelected, boolean hasFocus,
                            int row, int column) {
        
    	Download c = (Download)o;
 
    	
    	if(isSelected)
    	{
    		setBackground(table.getSelectionBackground());//new Color(0xb8,0xcf,0xe5));
    		setForeground(Color.GREEN);
    	}
    	else
    	{
    		setBackground(table.getBackground());
    		setForeground(foreground);
    	}
    	
    	if (isSelected) {
            if (selectedBorder == null) {
                selectedBorder = BorderFactory.createMatteBorder(4,2,4,2,
                                          table.getSelectionBackground());
            }
            setBorder(selectedBorder);
        } else {
            if (unselectedBorder == null) {
                unselectedBorder = BorderFactory.createMatteBorder(4,2,4,2,
                                          table.getBackground());
            }
            setBorder(unselectedBorder);
        }
    	
    	setMaximum((int)(c.size/1024));
    	setValue((int)(c.downloaded/1024));
  
    	

        
        return this;
    }
}
